package br.edu.unifei.mestrado.band.difusion;

import java.awt.Paint;

import org.apache.commons.collections15.Transformer;

import br.edu.unifei.banded.Banded2WayDiffusion;
import br.edu.unifei.mestrado.commons.graph.GraphWrapper;
import br.edu.unifei.mestrado.commons.partition.AbstractPartition;
import br.edu.unifei.mestrado.commons.partition.AbstractPartitionIndex;
import br.edu.unifei.mestrado.mem.graph.Graph;
import br.edu.unifei.mestrado.mem.graph.Node;
import br.edu.unifei.mestrado.mem.graph.PartitionIndexMem;
import br.edu.unifei.mestrado.mn.GraphViewMem;
import br.edu.unifei.mestrado.view.GraphMemPartitioningVisualization;

public class BandDifusionMemory extends Banded2WayDiffusion {

	private String graphFileName;
	protected GraphWrapper grafo = null;
	private AbstractPartitionIndex index = null;

	private GraphViewMem view = new GraphViewMem();

	public BandDifusionMemory(String graphFileName, int seed1, int seed2) {
		super(seed1, seed2);
		this.grafo = new Graph(GraphWrapper.NO_LEVEL, graphFileName);
		this.graphFileName = graphFileName;
		index = new PartitionIndexMem(AbstractPartition.TWO_WAY);

		view.setVertexLabelTransformer(new Transformer<Node, String>() {
			@Override
			public String transform(Node v) {
				// UTIL: o D aqui é a quantidade de liquido que tem no node.
				return "V" + v.getId() + ":" + v.getWeight() + ":" + v.getD();
			}
		});

		
		//não deu certo, trava a view
//		view.setVertexFillPaintTransformer(new Transformer<Node, Paint>() {
//			@Override
//			public Paint transform(Node node) {
//				return GraphMemPartitioningVisualization.similarColors[node.getPartition()
//						% GraphMemPartitioningVisualization.similarColors.length];
//			}
//		});
	}

	@Override
	public AbstractPartitionIndex getPartitionIndex() {
		return index;
	}

	@Override
	public GraphWrapper createNewGraph(Integer level) {
		Graph grafo = new Graph(level, graphFileName);
		return grafo;
	}

	@Override
	public void readGraph() {
		grafo.readGraph();
	}

	@Override
	public GraphWrapper getGrafo() {
		return grafo;
	}

	// metodos da view

	@Override
	public void initView(GraphWrapper initialGraph) {
		view.initView(initialGraph);
	}

	@Override
	public void setShowView(boolean showView) {
		view.setShowView(showView);
	}

	@Override
	public void updateView(GraphWrapper grafo, int level, String it, int cutWeight) {
		view.updateView(grafo, level, it, cutWeight);
	}

	@Override
	public void updateViewCoarsed(GraphWrapper grafo, int level, String it, int cutWeight) {
		view.updateViewCoarsed(grafo, level, it, cutWeight);
	}

	@Override
	public void repaint() {
		view.repaint();
	}

}
